app.controller('classifyController' , function($scope, $http, utilService, $location){
	
	var myModal = $('#myModal1');
	
	/*
	 *	类别展示
	 * */
	function showClassify(){
		
		utilService.ajax({
			url: '../../api/classify_list.php',
			data: {size: 5},
			method: 'post',
			ok: function(response) {
				if (response.success) {
					$scope.classifys = response.data;
				} else {
					// ...
				}
			}
		}, $scope);
		
	}
	$scope.$on("$viewContentLoaded", function(){
		showClassify();
	});
	
	
	//删除类别
	$scope.delClassify = function(){
		var id;
		var url = "../../api/classify_del.php";
		if(!confirm("确定要删除该数据吗")){
			return;
		}
		console.log(this);
		layer.load();
		id = this.classify.id;
		
		$http({
			url: url,
			method: "get",
			params: {id:id}
		}).success(function(rep) {
			layer.closeAll('loading');
			showClassify();
		})
	}
	
	//添加商品类别
	$scope.addClassify = function(){
		myModal.modal('show');
	}
	//保存按钮
	$scope.ajaxRequestPost = function(){
		layer.load();
		var requestUrl = "../../api/classify_add.php";
		var data = {name: $scope.classifyName}
		
	    var transFn = function (data) {  
	        return $.param(data);  
	    };  
	    var postCfg = {  
	        headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},  
	        transformRequest: transFn  
	    };  
	  
	    $http.post(requestUrl, data, postCfg).success(function (resultJson) {  
	        if (resultJson.success) {  
	           
	           layer.closeAll('loading');
	           myModal.modal('hide');
	           showClassify();
	        }  
	    }).error(function (e) {  
	        console.log('网络异常');  
	    });  
	}
	
});